/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.tomasio.projects.welcome.model;

import com.tomasio.projects.welcome.dto.FotoDTO;
import java.sql.Blob;
import java.sql.SQLException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sql.rowset.serial.SerialBlob;
import javax.sql.rowset.serial.SerialException;

/**
 *
 * @author administrador
 */
public class Foto {
    
    private Blob source;
    private Date data;

    public Foto() {
    }

    public Foto(Blob source, Date data) {
        this.source = source;
        this.data = data;
    }

    public Foto(FotoDTO dto) {
        if (dto != null){
            this.data = dto.getData();
            try {
                source = new SerialBlob(dto.getSource());
            } catch (SerialException ex) {
                Logger.getLogger(Foto.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(Foto.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }


    public Date getData() {
        return data;
    }

    public void setData(Date data) {
        this.data = data;
    }

    public Blob getSource() {
        return source;
    }

    public void setSource(Blob source) {
        this.source = source;
    }
    public FotoDTO createDTO(){
        FotoDTO dto = new FotoDTO();
        dto.setData(data);
        if (source != null) {
            try {
                dto.setSource(source.getBytes(1, (int) source.length()));
            } catch (SQLException ex) {
                Logger.getLogger(Foto.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return dto;
    }



}
